Include pull and other external commands in usage output
authorStef Walter <stefw@gnome.org>
Fri, 10 Aug 2012 21:12:01 +0000 (23:12 +0200)
committerColin Walters <walters@verbum.org>
Sun, 19 Aug 2012 19:05:01 +0000 (15:05 -0400)
src/ostree/main.c
src/ostree/ostree-pull.c
src/ostree/ot-main.c
src/ostree/ot-main.h

index 5d7260fe2f6706f32f9b49c19e9e0fc369439c8b..5736f3c502b639858d0dc6be3b737ce35ae596da 100644 (file)
@@ -30,7 +30,7 @@
 #include "ot-main.h"
 #include "ot-builtins.h"
 
-static OstreeBuiltin builtins[] = {
+static OstreeCommand commands[] = {
   { "cat", ostree_builtin_cat, 0 },
   { "config", ostree_builtin_config, 0 },
   { "checkout", ostree_builtin_checkout, 0 },
@@ -44,6 +44,7 @@ static OstreeBuiltin builtins[] = {
   { "prune", ostree_builtin_prune, 0 },
   { "fsck", ostree_builtin_fsck, 0 },
   { "pack", ostree_builtin_pack, 0 },
+  { "pull", NULL, 0 },
   { "remote", ostree_builtin_remote, 0 },
   { "rev-parse", ostree_builtin_rev_parse, 0 },
   { "remote", ostree_builtin_remote, 0 },
@@ -94,7 +95,7 @@ main (int    argc,
   GError *error = NULL;
   int ret;
 
-  ret = ostree_run (argc, argv, builtins, &error);
+  ret = ostree_run (argc, argv, commands, &error);
   if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
     {
       g_clear_error (&error);
@@ -102,7 +103,7 @@ main (int    argc,
     }
 
   if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
-    ostree_usage (argv, builtins, TRUE);
+    ostree_usage (argv, commands, TRUE);
 
   if (error != NULL)
     {
index 2d745f1fba1cf8be147f257e488070417ea8dccd..fa5d55c564aa3fd180e495dc8baef689c11248da 100644 (file)
@@ -1672,7 +1672,7 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   return ret;
 }
 
-static OstreeBuiltin builtins[] = {
+static OstreeCommand commands[] = {
   { "pull", ostree_builtin_pull, 0 },
   { NULL }
 };
@@ -1681,5 +1681,5 @@ int
 main (int    argc,
       char **argv)
 {
-  return ostree_main (argc, argv, builtins);
+  return ostree_main (argc, argv, commands);
 }
index 2f64fc52fc304d0882178f299d61831cb52893f6..90f3209bcc6f7645f181168f77a75b31a8f135b1 100644 (file)
 #include "otutil.h"
 
 int
-ostree_usage (char **argv, OstreeBuiltin *builtins, gboolean is_error)
+ostree_usage (char **argv,
+              OstreeCommand *commands,
+              gboolean is_error)
 {
-  OstreeBuiltin *builtin = builtins;
+  OstreeCommand *command = commands;
   void (*print_func) (const gchar *format, ...);
 
   if (is_error)
@@ -44,10 +46,10 @@ ostree_usage (char **argv, OstreeBuiltin *builtins, gboolean is_error)
               argv[0]);
   print_func ("Builtin commands:\n");
 
-  while (builtin->name)
+  while (command->name)
     {
-      print_func ("  %s\n", builtin->name);
-      builtin++;
+      print_func ("  %s\n", command->name);
+      command++;
     }
   return (is_error ? 1 : 0);
 }
@@ -75,10 +77,10 @@ prep_builtin_argv (const char *builtin,
 int
 ostree_run (int    argc,
             char **argv,
-            OstreeBuiltin  *builtins,
+            OstreeCommand *commands,
             GError **res_error)
 {
-  OstreeBuiltin *builtin;
+  OstreeCommand *command;
   GError *error = NULL;
   int cmd_argc;
   char **cmd_argv = NULL;
@@ -99,7 +101,7 @@ ostree_run (int    argc,
   g_set_prgname (argv[0]);
 
   if (argc < 2)
-    return ostree_usage (argv, builtins, 1);
+    return ostree_usage (argv, commands, TRUE);
 
   am_root = getuid () == 0;
   have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
@@ -140,32 +142,32 @@ ostree_run (int    argc,
       cmd = argv[arg_off-1];
     }
 
-  builtin = builtins;
-  while (builtin->name)
+  command = commands;
+  while (command->name)
     {
-      if (g_strcmp0 (cmd, builtin->name) == 0)
+      if (g_strcmp0 (cmd, command->name) == 0)
         break;
-      builtin++;
+      command++;
     }
 
-  if (!builtin->name)
+  if (!command->fn)
     {
       ot_lfree char *msg = g_strdup_printf ("Unknown command '%s'", cmd);
       g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, msg);
       goto out;
     }
 
-  if (repo == NULL && !(builtin->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
+  if (repo == NULL && !(command->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
     {
       g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "Command requires a --repo argument");
-      ostree_usage (argv, builtins, TRUE);
+      ostree_usage (argv, commands, TRUE);
       goto out;
     }
   
   prep_builtin_argv (cmd, argc-arg_off, argv+arg_off, &cmd_argc, &cmd_argv);
 
-  if (!builtin->fn (cmd_argc, cmd_argv, repo_file, &error))
+  if (!command->fn (cmd_argc, cmd_argv, repo_file, &error))
     goto out;
 
  out:
@@ -182,15 +184,15 @@ ostree_run (int    argc,
 int
 ostree_main (int    argc,
              char **argv,
-             OstreeBuiltin  *builtins)
+             OstreeCommand *commands)
 {
   GError *error = NULL;
   int ret;
 
-  ret = ostree_run (argc, argv, builtins, &error);
+  ret = ostree_run (argc, argv, commands, &error);
 
   if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
-    ostree_usage (argv, builtins, TRUE);
+    ostree_usage (argv, commands, TRUE);
 
   if (error)
     {
index 7712db141682a34598f719e87343e8a131629ee9..4deb086a25208cd009ca88d4a7f7e81924f579b3 100644 (file)
@@ -31,10 +31,10 @@ typedef struct {
   const char *name;
   gboolean (*fn) (int argc, char **argv, GFile *repo_path, GError **error);
   int flags; /* OstreeBuiltinFlags */
-} OstreeBuiltin;
+} OstreeCommand;
 
-int ostree_main (int    argc, char **argv, OstreeBuiltin  *builtins);
+int ostree_main (int    argc, char **argv, OstreeCommand  *commands);
 
-int ostree_run (int    argc, char **argv, OstreeBuiltin  *builtins, GError **error);
+int ostree_run (int argc, char **argv, OstreeCommand *commands, GError **error);
 
-int ostree_usage (char **argv, OstreeBuiltin *builtins, gboolean is_error);
+int ostree_usage (char **argv, OstreeCommand *commands, gboolean is_error);